package cc.fs.kotlin.ui

import android.app.NotificationManager
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.util.DisplayMetrics
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import org.jetbrains.anko.displayMetrics

/**
 * Created by fostion on 2/19/16.
 * 界面帮助类
 */
object UIHelper {

    /** 获取屏幕长宽 */
    fun getDisplayMetrics(context: Context): DisplayMetrics {
        return context.displayMetrics
    }

    /** 隐藏键盘  */
    fun hiddenSoftKeyboard(view: View) {
        val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        if (imm != null && imm.isActive) {
            imm.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }

    /** 清除所有通知*/
    fun cleanAllNotification(context: Context) {
        val notiManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notiManager.cancelAll()
    }

    /** 加载图片 */
    fun loadImage(imageView: ImageView, image:Any){
        when(image){
            is Bitmap -> imageView.setImageBitmap(image)
            is Drawable -> imageView.setImageDrawable(image)
            is Int -> imageView.setImageResource(image)
            is String -> {
                //加载网络图片
            }
        }

    }

}
